package dongze.com.ckdj.data.entity.response;

import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;

/**
 * Created by fanqwz on 2017/7/25.
 */

@JsonAdapter(VehicleInfoKeyPair.VehicleInfoMapAdapter.class)
public class VehicleInfoKeyPair {
    String key;
    String value;

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public static class VehicleInfoMapAdapter extends TypeAdapter<VehicleInfoKeyPair> {
        @Override
        public void write(JsonWriter out, VehicleInfoKeyPair value) throws IOException {
            out.beginObject();
            out.name(value.getKey()).value(value.getValue());
            out.endObject();
        }

        @Override
        public VehicleInfoKeyPair read(JsonReader in) throws IOException {
            VehicleInfoKeyPair vehicleInfoMap = null;

            in.beginObject();
            try {
                if (in.hasNext()) {
                    vehicleInfoMap = new VehicleInfoKeyPair();
                    vehicleInfoMap.setKey(in.nextName());
                    vehicleInfoMap.setValue(in.nextString());
                }
            } catch (Exception e) {
                e.printStackTrace();
                in.nextNull();
            }
            in.endObject();

            return vehicleInfoMap;
        }
    }
}
